import Vue from "vue";
import Vuex from "vuex"

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        cart_list: uni.getStorageSync('goods_list') || []
    },
    mutations: {
        add(state, data) {
            state.cart_list = data
            uni.setStorageSync('goods_list', data);
        }
    },
    getters: {
        allcount: state => {
            let num = 0;
            state.cart_list.forEach((v) => {
                if (v.check) {
                    num += v.count;
                }
            });
            return num;
        },
        allprice(state) {
            let num = 0;
            state.cart_list.forEach((v) => {
                if (v.check) {
                    num += v.goods_price * v.count;
                }
            });
            return num;
        }
    }
})
export default store